package ttp.service;

import ttp.dao.TtpDAO;
import ttp.to.TreeTO;
import ttp.utilities.Utilities;

public class TreeService {
	private TtpDAO dao;

	public TreeService(TtpDAO dao) {
		super();
		this.dao = dao;
	}
	
	public TreeTO run() throws Exception{
		String [] etp = {"A사","B사", "C사"};
		String [] tt = {"소나무","은행나무","오크나무"};
		String [] tg = {"A등급","B등급", "C등급"};
		int [] tw = {100,200,300};
		int treeNo = dao.sequenceTree();
		int q = (int) (Math.random() * 3);
		String enterPrise = etp[q];
		int j = (int) (Math.random() * 3);
		String treeType = tt[j]; 
		int k = (int) (Math.random() * 3);
		String treeGrade = tg[k];
		int s = (int) (Math.random() * 3);
		int treeCount = tw[s];
		String orderDate = Utilities.getNow();
		int treeCheck = 0;
		int errorRate = 0;
		int result = 0;
		
		TreeTO tto = new TreeTO(treeNo, enterPrise, treeType, treeGrade, treeCount, orderDate, treeCheck, errorRate, result);
		
		dao.insertTree(tto);
		Thread.sleep(1000);
		return tto;
	}
	

}
